﻿//-----------------------------------------------------------------
//
// @(#)$Id: TableHanders.aspx.cs,v 1.0 2013/12/16 9:57:20 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:57:20 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using ebay.Dal;
using ebay.Dal.CenterDB_BasTableAdapters;
using ebay.Dal.CenterDB_EbayTableAdapters;
using ebay.Dal.CenterDB_LTableAdapters;
using ebay.Dal.CenterDB_OrderTableAdapters;
using ebay.Dal.CenterDB_SystemTableAdapters;
using ebay.Dal.K3DataBaseTableAdapters;
using ebay.Utility;

public partial class TableHanders : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e) {
        string tableName = Request["tid"];
        string type = Request["type"];
        string act = Request["act"];
        DataTable tableSource = null;
        string _jsonRows = null;

        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "utf-8";
        HttpContext.Current.Response.ContentType = "application/json";
        HttpContext.Current.Response.Expires = 0;
        HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now;
        HttpContext.Current.Response.CacheControl = "no-cache";
        if (string.IsNullOrEmpty(act) || string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(type)) {

            tableSource = GetMsgTable("1", "参数错误");
            _jsonRows = GetJson(tableSource);
            Response.Write(_jsonRows);
            return;
        }
        tableName = tableName.ToLower();

        int rowCount = 0;

        switch (act) {
#region query
          case "q":
              //act=q&tableName=orders&type=0&page=1&rows=10&sort=OrderID&order=desc
              string pageNumber = Request["page"];
              string pageSize = Request["rows"];
              string sortName = Request["sort"];
              string sortOrder = Request["order"];
              int maxPage = 0;
              string description = "";
              switch (tableName) {
                case "04"://ebayaccountfee  
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string orderlineItemId = Request["OrderLineItemId"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayAccountFee.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(orderlineItemId)) {
                            orderlineItemId = WebUtility.InputText(orderlineItemId, 30);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayAccountFee.OrderlineItemId = '" + orderlineItemId + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);
                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), EbayAccountFee.CreateDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), EbayAccountFee.CreateDate, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "EbayAccountFee",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "08"://EbayDispute
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string orderlineItemId = Request["OrderLineItemId"];
                        String salesRecordNumber = Request["SalesRecordNumber"];
                        string disputeReason = Request["disputeReason"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayDispute.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(disputeReason) && disputeReason != "Select") {
                            disputeReason = WebUtility.InputText(disputeReason, 50);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayDispute.DisputeReason = '" + disputeReason + "'";
                        }
                        if (!string.IsNullOrEmpty(orderlineItemId)) {
                            orderlineItemId = WebUtility.InputText(orderlineItemId, 30);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayDispute.OrderlineItemId = '" + orderlineItemId + "'";
                        }
                        if (!String.IsNullOrEmpty(salesRecordNumber)) {
                            salesRecordNumber = WebUtility.InputText(salesRecordNumber, 50);
                            Where += Where.Length > 0 ? " AND" : "";
                            Where += String.Format(" Orders.SalesRecordNumber LIKE '{0}%'", salesRecordNumber);
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);
                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), EbayDispute.DisputeModifiedTime, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), EbayDispute.DisputeModifiedTime, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "EbayDispute LEFT JOIN Orders ON EbayDispute.OrderlineItemId = Orders.OrderLineItemId",
                                                "EbayDispute.EbayUserId,DisputeID,DisputeRecordType,DisputeState,DisputeStatus,OtherPartyRole,OtherPartyName,UserRole,EbayDispute.TransactionID,Item,DisputeReason,DisputeExplanation,DisputeCreditEligibility,DisputeCreatedTime,DisputeModifiedTime,EbayDispute.OrderLineItemID,ImportDate",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "09"://EbayDisputeMessage
                    {
                        string Where = "";
                        string ebayUserId = Request["id2"];
                        string disputeId = Request["id"];
                        if (string.IsNullOrEmpty(ebayUserId) || string.IsNullOrEmpty(disputeId)) {
                            tableSource = new DataTable();
                        } else {
                            Where = "EbayUserId = '" + ebayUserId + "' And DisputeID='" + disputeId + "'";
                        }

                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "EbayDisputeMessage",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "11"://EbayFeedBack
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string orderlineItemId = Request["OrderLineItemId"];
                        string commentType = Request["CommentType"];
                        string User = Request["User"].Trim();
                        string ItemID = Request["ItemID"].Trim();
                        if (!string.IsNullOrEmpty(User)) {
                            User = WebUtility.InputText(User, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayFeedBack.[CommentingUser] = '" + User + "'";
                        }
                        if (!string.IsNullOrEmpty(ItemID)) {
                            ItemID = WebUtility.InputText(ItemID, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayFeedBack.[ItemID] = '" + ItemID + "'";
                        }
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayFeedBack.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);

                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), EbayFeedBack.CommentTime, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), EbayFeedBack.CommentTime, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(orderlineItemId)) {
                            orderlineItemId = WebUtility.InputText(orderlineItemId, 30);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayFeedBack.OrderlineItemId = '" + orderlineItemId + "'";
                        }
                        if (!String.IsNullOrEmpty(commentType)) {
                            commentType = WebUtility.InputText(commentType, 20);
                            Where += Where.Length > 0 ? " AND" : "";
                            Where += " EbayFeedBack.CommentType = '" + commentType + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 30 : int.Parse(pageSize),
                                                "EbayFeedBack",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "13"://EbayOrders
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string orderStatus = Request["OrderStatus"];
                        string orderId = Request["OrderId"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayOrders.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);
                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), EbayOrders.ImportDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), EbayOrders.ImportDate, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(orderId)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayOrders.OrderId = '" + orderId + "'";
                        }
                        if (!string.IsNullOrEmpty(orderStatus) && orderStatus != "All") {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayOrders.OrderStatus = '" + orderStatus + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "EbayOrders",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "12"://EbayOrderDetails
                    {
                        string Where = "";
                        string ebayUserId = Request["id"];
                        string orderId = Request["id2"];
                        if (string.IsNullOrEmpty(ebayUserId) || string.IsNullOrEmpty(orderId)) {
                            tableSource = new DataTable();
                        } else {
                            Where = "EbayUserId = '" + ebayUserId + "' And OrderId='" + orderId + "'";
                        }

                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "EbayOrderDetails",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "19"://PayPalOrderDetails
                    {
                        string Where = "";
                        string ebayUserId = Request["id"];
                        string TransactionId = Request["id2"];
                        if (string.IsNullOrEmpty(ebayUserId) || string.IsNullOrEmpty(TransactionId)) {
                            tableSource = new DataTable();
                        } else {
                            Where = "EbayUserId = '" + ebayUserId + "' And TransactionId='" + TransactionId + "'";
                        }

                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "PayPalOrderDetails",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "20"://PayPalOrders
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string status = Request["status"];
                        string transId = Request["transId"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PayPalOrders.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);

                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " CONVERT (Varchar(8), PayPalOrders.ImportDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), PayPalOrders.ImportDate, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(transId)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PayPalOrders.TransactionId = '" + transId + "'";
                        }
                        if (!string.IsNullOrEmpty(status) && status != "All") {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PayPalOrders.PayStatus = '" + status + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "PayPalOrders",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "22"://Product
                    {
                        string where = "";
                        string productId = Request["ProductId"];
                        string userCode = Request["UserCode"];
                        if (!string.IsNullOrEmpty(productId)) {
                            productId = WebUtility.InputText(productId, 80);
                            if (where.Length > 0)
                                where += " And";
                            where += " ProductId = '" + productId + "'";
                        }
                        if (!string.IsNullOrEmpty(userCode)) {
                            userCode = WebUtility.InputText(userCode, 255);
                            if (where.Length > 0)
                                where += " And";
                            where += String.Format(" UserCode LIKE '{0}%'", userCode);// +productName + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "Product",
                                                "ProductId,ProductSpecification,ProductName,SalesStatus,Auser",
                                                sortName + " " + sortOrder,
                                                where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "28"://CustomLableMapping
                    {
                        string Where = "";
                        int packageId = Convert.ToInt32(Request["packageId"]);
                        int wh_Code = Convert.ToInt32(Request["wh_Code"]);
                        string customlable = Request["cuslable"];

                        if (packageId != 0) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PackageId=" + packageId;

                        }
                        if (wh_Code != 0) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Wh_Code=" + wh_Code;
                        }
                        if (!string.IsNullOrEmpty(customlable)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CustomerId= '" + customlable + "'";

                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 30 : int.Parse(pageSize),
                                                "CustomLableMapping",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "29"://Product2
                    {
                        string Where = "";
                        string productId = Request["productId"];

                        if (!String.IsNullOrEmpty(productId)) {
                            productId = WebUtility.InputText(productId, 80);
                            if (Where.Length > 0)
                                Where += "And";
                            else {
                                Where += "ProductId='" + productId + "'";
                            }
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "Product2",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);

                    }
                    break;
                case "38"://EbayActiveListing
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string itemId = Request["ItemId"];
                        string itemTitle = Request["ItemTitle"];
                        string customLable = Request["CustomLable"];
                        string iType = Request["iType"];
                        string listing = Request["listing"];
                        string OnLineStatus = Request["OnLineStatus"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayActiveListing.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(OnLineStatus)) {
                            OnLineStatus = WebUtility.InputText(OnLineStatus, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayActiveListing.[OnlineStatus] = '" + OnLineStatus + "'";
                        }
                        if (!string.IsNullOrEmpty(customLable)) {
                            customLable = WebUtility.InputText(customLable, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayActiveListing.CustomLable like '%" + customLable + "%'";
                        }
                        if (!string.IsNullOrEmpty(listing)) {
                            listing = WebUtility.InputText(listing, 80);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Listing like '%" + listing + "%'";
                        }
                        if (!string.IsNullOrEmpty(iType)) {
                            customLable = WebUtility.InputText(iType, 80);

                            if (iType == "1") {
                                if (Where.Length > 0)
                                    Where += " And";
                                Where += " Listing is null";
                            }
                        }
                        if (!string.IsNullOrEmpty(itemId)) {
                            itemId = WebUtility.InputText(itemId, 30);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayActiveListing.ItemId = '" + itemId + "'";
                        }
                        if (!string.IsNullOrEmpty(itemTitle)) {
                            itemTitle = WebUtility.InputText(itemTitle, 255);

                            if (Where.Length > 0)
                                Where += " And";
                            Where += " EbayActiveListing.ItemTitle like '%" + itemTitle + "%'";
                        }
                        Pagination p = new Pagination();
                        //tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                        //                          string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                        //                          "EbayActiveListing left outer join CustomLableMapping on dbo.ReplaceCustomLable(EbayUserId,CustomLable) = CustomLableMapping.CustomerId",
                        //                          "EbayUserId,ItemId,DownLoadDate,dbo.ReplaceCustomLable(EbayUserId,CustomLable) as CustomLable"
                        //                        + ",CustomLableMapping.Listing,ProductIDType,ProductIDValue,ProductIDValue2,QuantityAvailable,Purchases"
                        //                        + ",Bids,Price,StartDate,EndDate,Condition,Type"
                        //                        + ",ItemTitle,CategoryLeafName,CategoryNumber,PrivateNotes,SiteListed"
                        //                        + ",VariationDetails,ProductReferenceID,ConditionID",
                        //                          sortName + " " + sortOrder,
                        //                          Where,
                        //                          ref maxPage,
                        //                          ref rowCount,
                        //                          ref description);
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 50 : int.Parse(pageSize),
                                                "EbayActiveListing ",
                                                "EbayUserId,ItemId,DownLoadDate,dbo.ReplaceCustomLable(EbayUserId,CustomLable) as CustomLable"
                                                + ",Listing,[OnlineStatus],[SellingFormat],[WhCode],[ParcelType],[LogonCountry],[OnSalePrice],[Msg],[ProdLevel]"
                                                + ",ProductIDType,ProductIDValue,ProductIDValue2,QuantityAvailable,Purchases"
                                                + ",Bids,Price,StartDate,EndDate,Condition,Type"
                                                + ",ItemTitle,CategoryLeafName,CategoryNumber,PrivateNotes,SiteListed"
                                                + ",VariationDetails,ProductReferenceID,ConditionID",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "03"://EbayAccount
                    {
                        T_EbayAccountTableAdapter adapter = new T_EbayAccountTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "14"://EbayPaypalAccountRelation
                    {

                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "EbayPaypalAccountRelation",
                                                "*",
                                                sortName + " " + sortOrder,
                                                "",
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                        //T_EbayPaypalAccountRelationTableAdapter adapter = new T_EbayPaypalAccountRelationTableAdapter();
                        //tableSource = adapter.GetData();
                    }
                    break;
                case "18"://PayPalAccount
                    {
                        T_PayPalAccountTableAdapter adapter = new T_PayPalAccountTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "21"://PPInfoCol
                    {
                        T_PPInfoColContextTableAdapter adapter = new T_PPInfoColContextTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "31"://EbayUnSendCountry
                    {
                        T_EbayUnSendCountryTableAdapter adapter = new T_EbayUnSendCountryTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "32"://OrderSource
                    {
                        T_OrderSourceTableAdapter adapter = new T_OrderSourceTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "33"://RoymailAndPayPalSendCountry
                    {
                        T_RoymailAndPayPalSendCountryTableAdapter adapter = new T_RoymailAndPayPalSendCountryTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "34"://ExpressShippingMethods
                    {
                        T_ExpressShippingMethodsTableAdapter adapter = new T_ExpressShippingMethodsTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "35"://Postage
                    {
                        T_PostageTableAdapter adapter = new T_PostageTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "36"://CreateDocumentsType
                    {
                        T_CreateDocumentsTypeTableAdapter adapter = new T_CreateDocumentsTypeTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "37"://Modle
                    {
                        T_ModleTableAdapter adapter = new T_ModleTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "39"://Country
                    {
                        T_CountryTableAdapter adapter = new T_CountryTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "40"://RefundType
                    {
                        T_RefundTypeTableAdapter adapter = new T_RefundTypeTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "41": {
                    string Where = "";
                    string ebayUserId = Request["ebayUserId"];
                    string timeFrom = Request["timeFrom"];
                    string timeTo = Request["timeTo"];
                    string orderStatus = Request["OrderStatus"];
                    string orderId = Request["OrderId"];
                    if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                        ebayUserId = WebUtility.InputText(ebayUserId, 80);

                        if (Where.Length > 0)
                            Where += " And";
                        Where += " EbaySelling.EbayUserId = '" + ebayUserId + "'";
                    }
                    if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                        timeFrom = WebUtility.InputText(timeFrom, 12);
                        timeTo = WebUtility.InputText(timeTo, 12);
                        DateTime TimeFrom = DateTime.Parse(timeFrom);
                        DateTime TimeTo = DateTime.Parse(timeTo);
                        if (Where.Length > 0)
                            Where += " And";
                        Where += " CONVERT (Varchar(8), EbaySelling.ImportDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), EbaySelling.ImportDate, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                    }
                    if (!string.IsNullOrEmpty(orderId)) {
                        if (Where.Length > 0)
                            Where += " And";
                        Where += " EbaySelling.OrderId = '" + orderId + "'";
                    }
                    if (!string.IsNullOrEmpty(orderStatus) && orderStatus != "All") {
                        if (Where.Length > 0)
                            Where += " And";
                        Where += " EbaySelling.CompleteStatus = '" + orderStatus + "'";
                    }
                    Pagination p = new Pagination();
                    tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                            string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                            "EbaySelling",
                                            "*",
                                            sortName + " " + sortOrder,
                                            Where,
                                            ref maxPage,
                                            ref rowCount,
                                            ref description);
                }
                    break;
                case "42"://PPOrder
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string status = Request["status"];
                        string transId = Request["transId"];
                        string statusId = Request["statusId"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);

                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " CONVERT (Varchar(8), PPOrder.ImportDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), PPOrder.ImportDate, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(transId)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PPOrder.TransactionId = '" + transId + "'";
                        }
                        if (!string.IsNullOrEmpty(status) && status != "All") {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PPOrder.Status = '" + status + "'";
                        }
                        if (!string.IsNullOrEmpty(statusId) && statusId != "2") {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PPOrder.StatusId = " + statusId;
                        }
                        PPOrder pp = new PPOrder();
                        string outTable = pp.GetQueryInfo("PPOrder", "PPInfoCol");
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                @"PPOrder Left Outer Join PPInfoCol  On " + outTable,
                                                "PPOrder.EbayUserId, PPOrder.TransactionId,"
                                                + "IsNull(PPInfoCol.CategoryName,'') As CategoryName, PPOrder.CreateDateTime, PPOrder.TimeZone, PPOrder.Name, "
                                                + "PPOrder.Type, PPOrder.Status, PPOrder.Subject, PPOrder.Currency, PPOrder.Gross, PPOrder.Fee, PPOrder.Net, "
                                                + "PPOrder.Reserve, PPOrder.Note, PPOrder.FromEmailAddress, PPOrder.ToEmailAddress, PPOrder.PaymentType, "
                                                + "PPOrder.CounterpartyStatus, PPOrder.PostalAddress, PPOrder.AddressStatus, PPOrder.ItemTitle, PPOrder.ItemID, "
                                                + "PPOrder.PostageandPackingAmount, PPOrder.InsuranceAmount, PPOrder.VAT, PPOrder.Option1Name, "
                                                + "PPOrder.Option1Value, PPOrder.Option2Name, PPOrder.Option2Value, PPOrder.AuctionSite, PPOrder.BuyerID, "
                                                + "PPOrder.ItemURL, PPOrder.ClosingDate, PPOrder.ReferenceTxnID, PPOrder.InvoiceNumber, "
                                                + "PPOrder.SubscriptionNumber, PPOrder.CustomNumber, PPOrder.ReceiptID, PPOrder.Balance, PPOrder.AddressLine1, "
                                                + "PPOrder.AddressLine2, PPOrder.City, PPOrder.County, PPOrder.PostalCode, PPOrder.Country, "
                                                + "PPOrder.ContactPhoneNumber, PPOrder.BalanceImpact, PPOrder.StatusId, PPOrder.ImportDate, "
                                                + "PPOrder.MatchDate",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "43"://ReturnsOrder
                    {
                        string Where = "";
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string processingStatus = Request["processingStatus"];
                        string summary = Request["Remarks"];
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);
                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), ReturnsOrder.SynchronousDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), ReturnsOrder.SynchronousDate, 112) <= '" +
                                TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(processingStatus.Trim())) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " ReturnsOrder.ProcessingStatus = '" + processingStatus + "'";
                        }
                        if (!string.IsNullOrEmpty(summary.Trim())) {
                            if (Where.Length > 0)
                                Where += "AND";
                            Where += String.Format(" ReturnsOrder.Remarks LIKE '%{0}%'", summary);
                        }

                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "ReturnsOrder",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "44"://Refund
                    {
                        string Where = "";
                        string timeFrom = Request["timeFrom"];
                        string ebayUserId = Request["ebayUserId"];
                        string timeTo = Request["timeTo"];
                        string statusId = Request["statusId"];
                        string rec_number = Request["rec_number"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim()) && ebayUserId != "Select") {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Refund.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(rec_number.Trim())) {
                            rec_number = WebUtility.InputText(rec_number, 80);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " o.OrderSalesRecordNumber = '" + rec_number + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);
                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), Refund.RefundDate, 112) >= '" + TimeFrom.ToString("yyyyMMdd") + "' AND CONVERT (Varchar(8), Refund.RefundDate, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(statusId.Trim())) {
                            statusId = WebUtility.InputText(statusId, 10);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Refund.StatusId = '" + statusId + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                @" Refund left join RefundType on Refund.RefundType=RefundType.Id"
                                                + " left outer join (select OrderSalesRecordNumber,EbayUserId, OrderId from Orders group by OrderSalesRecordNumber,EbayUserId, OrderId) o on Refund.OrderId = o.OrderId And Refund.EbayUserId = o.EbayUserId "
                                                + " left outer join [AIS2011120420456].dbo.t_item c on c.FItemClassId = 2 And c.FLevel = 1 and c.FitemId = Refund.BlameDepartments",
                                                "  Refund.EbayUserId,Refund.OrderId,Refund.RefundId,Refund.TransactionId,Refund.BuyerId,Refund.BuyerFullName,Refund.AuditFlag,"
                                                + "Refund.RefundAmount,Refund.StatusId,Refund.Atime,Refund.DisputeType,Refund.RefundDate,Refund.InvalidDate,Refund.Currency,o.OrderSalesRecordNumber,RefundType.RefundType as TypeName,c.FName as DepartmentName",
                                                "Refund." + sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "45"://ProductTracking
                    {
                        string Where = "";
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string procurementStatus = Request["procurementStatus"];
                        string productid = Request["productid"];
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 12);
                            timeTo = WebUtility.InputText(timeTo, 12);
                            DateTime TimeFrom = DateTime.Parse(timeFrom);
                            DateTime TimeTo = DateTime.Parse(timeTo);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " CONVERT (Varchar(8), ProductTracking.DateTime, 112) >= '" + TimeFrom.ToString("yyyyMMdd") +
                                "' AND CONVERT (Varchar(8), ProductTracking.DateTime, 112) <= '" + TimeTo.ToString("yyyyMMdd") + "'";
                        }
                        if (!string.IsNullOrEmpty(procurementStatus) && procurementStatus != "《--请选择--》") {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " ProductTracking.ProcurementStatus = '" + procurementStatus + "'";
                        }
                        if (!string.IsNullOrEmpty(productid)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " ProductTracking.ProductId = '" + productid + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "ProductTracking",
                                                "*",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "46": // orders
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"].Trim();
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string orderId = Request["orderId"].Trim();
                        string BuyerId = Request["BuyerId"].Trim();
                        string BuyerName = Request["BuyerName"].Trim();
                        string NewOrderId = Request["NewOrderId"].Trim();
                        string OrderStatusId = Request["OrderStatusId"].Trim();
                        string Standard = Request["Standard"] == null ? "" : Request["Standard"].Trim();
                        string rtype = Request["rtype"].Trim();
                        string itemId = Request["ItemId"].Trim();
                        string userCode = Request["userCode"].Trim();
                        string reason = Request["Reason"].Trim();
                        string qtype = Request["qtype"].Trim();
                        string resend = Request["resend"].Trim();
                        string memo = Request["memo"].Trim();
                        string ResendReason = Request["ResendReason"].Trim();
                        string FZR = Request["FZR"];
                        string DE = Request["DE"];

                        if (!string.IsNullOrEmpty(OrderStatusId.Trim())) {
                            OrderStatusId = WebUtility.InputText(OrderStatusId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.OrderStatusId = " + OrderStatusId;
                        }

                        if (!string.IsNullOrEmpty(itemId)) {
                            itemId = WebUtility.InputText(itemId, 80);
                            if (Where.Length > 0) {
                                Where += " And ";
                            }
                            Where += " Orders.ItemId = '" + itemId + "'";
                        }
                        if (!string.IsNullOrEmpty(qtype)) {
                            qtype = WebUtility.InputText(qtype, 80);
                            if (qtype == "1") {
                                if (Where.Length > 0) {
                                    Where += " And ";
                                }
                                Where += " Orders.SendQuantity > 0";
                            }
                        }
                        if (!string.IsNullOrEmpty(resend)) {
                            if (resend == "true") {
                                Where += Where.Length > 0 ? " AND " : "";
                                Where += @" Orders.OrderSalesRecordNumber LIKE '%\_%' ESCAPE '\'";
                            }
                        }
                        if (!string.IsNullOrEmpty(memo)) {
                            memo = WebUtility.InputText(memo, 80);
                            if (memo == "1") {
                                DateTime startdate = Convert.ToDateTime(Request["timeFrom"]);
                                DateTime enddate = Convert.ToDateTime(Request["timeTo"]);
                                T_OrderMemoTableAdapter upmemo = new T_OrderMemoTableAdapter();
                                int val = upmemo.UpdateMemo(startdate, enddate);
                                if (Where.Length > 0) {
                                    Where += " And ";
                                }
                                Where += " Orders.memo <>'' and Orders.mnote  <> '手工清除标准化'";
                            }
                        }
                        if (!string.IsNullOrEmpty(DE)) {
                            DE = WebUtility.InputText(DE, 80);
                            if (DE == "1") {
                                if (Where.Length > 0) {
                                    Where += " And ";
                                }
                                Where += string.Format(@"exists(select 1 
                                                                  from [CenterDB].[dbo].[EbayActiveListing] as a                                                                    
                                                                  where Orders.[ItemId] = a.[ItemId] 
                                                                    and [LogonCountry]='DE'
                                                                  )
                                                           ");
                            }
                        }
                        if (!string.IsNullOrEmpty(userCode)) {
                            userCode = WebUtility.InputText(userCode, 80);
                            if (Where.Length > 0) {
                                Where += " And ";
                            }
                            Where += "exists(select 1 from CustomerResolve "
                                + "left outer join Product on CustomerResolve.ProductId = Product.ProductId "
                                + "where Orders.OrderLineItemId = CustomerResolve.OrderLineItemId and Orders.EbayUserId = CustomerResolve.EbayUserId "
                                + "and Product.UserCode LIKE '" + userCode + "%')";
                        }
                        if (!string.IsNullOrEmpty(FZR)) {
                            FZR = WebUtility.InputText(FZR, 80);
                            if (Where.Length > 0) {
                                Where += " And ";
                            }
                            Where += string.Format(@"exists(select 1 
                                                                  from [CenterDB].[dbo].CustomerResolve as a
                                                                    inner join [AIS2011120420456].dbo.t_ICItemCore as b on a.ProductId =b.FNumber 
	                                                                inner join [AIS2011120420456].dbo.t_ICItemCustom  as c on b.FItemID =c.FItemID
                                                                  where Orders.OrderLineItemId = a.OrderLineItemId 
                                                                    and Orders.EbayUserId = a.EbayUserId
                                                                    and c.F_128 ='{0}'
                                                                  )
                                                        ", FZR);
                        }
                        if (!string.IsNullOrEmpty(ResendReason)) {
                            ResendReason = WebUtility.InputText(ResendReason, 80);
                            if (Where.Length > 0) {
                                Where += " And ";
                            }
                            Where += " Orders.[ReBuilderReson] like '%" + ResendReason + "%' And Orders.OrderLineItemId like '%[_]%'";
                        }
                        if (!string.IsNullOrEmpty(reason)) {
                            reason = WebUtility.InputText(reason, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.OrderRetentionReson LIKE '%" + reason + "%'";
                        }
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(BuyerId.Trim())) {
                            BuyerId = WebUtility.InputText(BuyerId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.UserId = '" + BuyerId + "'";
                        }
                        if (!string.IsNullOrEmpty(BuyerName.Trim())) {
                            BuyerName = WebUtility.InputText(BuyerName, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.BuyerFullName = '" + BuyerName + "'";
                        }
                        if (!string.IsNullOrEmpty(NewOrderId.Trim())) {
                            NewOrderId = WebUtility.InputText(NewOrderId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.NewOrderId = '" + NewOrderId + "'";
                        }
                        string timeWhere = "";
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 30);
                            timeTo = WebUtility.InputText(timeTo, 30);

                            if (rtype == "1") {
                                timeWhere = " CONVERT(varchar(19),Orders.Matchdate,21) >= '" + timeFrom + "' AND CONVERT(varchar(19),Orders.Matchdate,21) <= '" + timeTo + "'";
                            }
                            if (rtype == "2") {
                                timeWhere = " CONVERT(varchar(19),Orders.SaleDate,21) >= '" + timeFrom + "' AND CONVERT(varchar(19),Orders.SaleDate,21) <= '" + timeTo + "'";
                            }
                            if (rtype == "3") {
                                timeWhere = " CONVERT(varchar(19),Orders.Mtime,21) >= '" + timeFrom + "' AND CONVERT(varchar(19),Orders.Mtime,21) <= '" + timeTo + "'";
                            }

                        }
                        if (Standard != "Select") {
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            if (Standard == "解析正确") {
                                //Where += " Orders.OrderId not in (select OrderId from Orders where Standard <> '' And " + timeWhere + ")";
                                Where += " not exists (select 1 from Orders o where Orders.EbayUserId = o.EbayUserId and Orders.OrderId = o.OrderId and o.Standard <> o.Memo)";
                            } else if (Standard == "金额不对") {
                                Where += " Standard = '金额不对'";
                            } else if (Standard == "在系统中找不到相应的商品信息，请修正商品信息") {
                                Where += " Standard = '在系统中找不到相应的商品信息，请修正商品信息'";
                            } else if (Standard == "不完全代码") {
                                Where += " Standard = '不完全代码'";
                            } else if (Standard == "发货方式为空") {
                                Where += " OrderRetentionReson = '发货方式为空'";
                            } else if (Standard == "留言") {
                                Where += " Standard=Memo and Memo <> ''";
                            } else if (Standard == "手工清除标准化") {
                                Where += " Mnote='手工清除标准化' ";
                            } else if (Standard == "Check Country") {
                                Where += " [Standard]='Check Country'";
                            } else if (Standard == "包含禁用产品") {
                                Where += " [Standard]='包含禁用产品'";
                            }
                        }
                        if (!string.IsNullOrEmpty(orderId)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Orders.OrderSalesRecordNumber like '%" + orderId + "%'";
                        }
                        if (Where.Length > 0) {
                            Where += " And";
                        }
                        Where += timeWhere;
                        Pagination p = new Pagination();
                        tableSource = p.GetCommonData(
                                                      "Orders",
                                                      "",
                                                      "Orders.EbayUserId,Orders.OrderId,Orders.OrderSalesRecordNumber,Orders.NewOrderId,Orders.UserId,Orders.BuyerFullName,Orders.BuyerEmail,Sum(Orders.TotalPrice) as TotalPrice,Sum(Orders.Quantity) as TotalQuantity,Orders.IsPay,Orders.MatchStatusId,Orders.OrderStatusId,Orders.PDate,Orders.[Atime],Orders.MatchDate",
                                                      string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                      string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                      Where,
                                                      "Orders.EbayUserId,Orders.OrderId,Orders.OrderSalesRecordNumber,Orders.UserId,Orders.BuyerFullName,Orders.BuyerEmail,Orders.IsPay,Orders.MatchStatusId,Orders.OrderStatusId,Orders.NewOrderId,Orders.PDate,Orders.[Atime],Orders.MatchDate",
                                                      sortName + " " + sortOrder,
                                                      ref rowCount);
                    }
                    break;
                case "49"://EbayCountry
                    {
                        T_EbayCountryTableAdapter adapter = new T_EbayCountryTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "50"://EbayCountry
                    {
                        T_EbayCountryTableAdapter adapter = new T_EbayCountryTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "51"://CountryCategory
                    {
                        T_CountryCategoryTableAdapter adapter = new T_CountryCategoryTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "52"://reBuilderReason 重发原因维护
                    {
                        T_ReBuilderReasonTableAdapter adapter = new T_ReBuilderReasonTableAdapter();
                        tableSource = adapter.GetData();
                    }
                    break;
                case "1001"://k3表开头 获取计量单位组
                    {
                        string groupId = Request["id"];
                        T_MeasureUnitTableAdapter unitAdapter = new T_MeasureUnitTableAdapter();
                        tableSource = unitAdapter.GetDataByGroupId(Convert.ToInt32(groupId));
                    }
                    break;
                case "1002"://获取country
                    {
                        string countrytype = Request["countrytype"];
                        string countryNames = Request["countryNames"];
                        if (countrytype != null) {
                            switch (countrytype) {
                              case "delivery": {
                                  string romailcmdText1 = @"Select  case when CharIndex(',' + v.CountryName + ',',',' + @CountryNames + ',') > 0 then'Selected'
                                                                      else '' end as StatusId,CountryName from ( Select country as CountryName from  (
                                                                                 select country from (select RoymailSendCountryName as country  from RoymailAndPayPalSendCountry) a union 
                                                                                 (select PayPalSendCountryName as country from RoymailAndPayPalSendCountry)
                                                                                ) c ,EbayUnSendCountry where c.country!=EbayUnSendCountry .CountryName) v";
                                  string romailcmdtext2 = @"Select ''as StatusId,CountryName from ( Select country as CountryName from  (
                                                                                 select country from (select RoymailSendCountryName as country  from RoymailAndPayPalSendCountry) a union 
                                                                                 (select PayPalSendCountryName as country from RoymailAndPayPalSendCountry)
                                                                                ) c ,EbayUnSendCountry where c.country!=EbayUnSendCountry .CountryName) v ";
                                  if (!string.IsNullOrEmpty(countryNames)) {
                                      System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter("@CountryNames", SqlDbType.VarChar);
                                      p.Value = countryNames;
                                      tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, romailcmdText1, p);
                                  } else {
                                      tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, romailcmdtext2, null);
                                  }
                              }
                                  break;
                              case "postage": {
                                  string romailcmdText1 = @"Select  case when CharIndex(',' + ExpressShippingMethods .CountryNames + ',',',' + @CountryNames + ',') > 0 then'Selected'
                                                                      else '' end as StatusId,ExpressShippingMethods .CountryNames as CountryName From ExpressShippingMethods";
                                  string romailcmdtext2 = "select''as StatusId, ExpressShippingMethods .CountryNames as CountryName from ExpressShippingMethods ";
                                  if (!string.IsNullOrEmpty(countryNames)) {
                                      System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter("@CountryNames", SqlDbType.VarChar);
                                      p.Value = countryNames;
                                      tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, romailcmdText1, p);
                                  } else {
                                      tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, romailcmdtext2, null);
                                  }
                              }
                                  break;
                              default: {
                                  string cmdText = @"Select  case when CharIndex(',' + EbayCountry.CountryName + ',',',' + @CountryNames + ',') > 0 then'Selected'
                                                            else '' end as StatusId, EbayCountry.CountryName From EbayCountry";
                                  string cmdText1 = "Select  '' as StatusId,EbayCountry.CountryName From EbayCountry";
                                  if (!string.IsNullOrEmpty(countryNames)) {
                                      System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter("@CountryNames", SqlDbType.VarChar);
                                      p.Value = countryNames;
                                      tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                                  } else {
                                      tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText1, null);
                                  }
                              }
                                  break;
                            }
                        }
                    }
                    break;
                case "1003"://获取feedback明细
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            T_EbayFeedBackContextTableAdapter feedbackAdapter = new T_EbayFeedBackContextTableAdapter();
                            tableSource = feedbackAdapter.GetData(ebayUserId, orderId);
                        }
                    }
                    break;
                case "1004"://获取dispute明细
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            T_DisputeContextTableAdapter disputeAdapter = new T_DisputeContextTableAdapter();
                            tableSource = disputeAdapter.GetDispute(ebayUserId, orderId);
                        }
                    }
                    break;
                case "1005"://获取Orders明细
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            string cmdText = @"Select distinct a.EbayUserId,a.OrderId,a.OrderSalesRecordNumber,a.OrderLineItemId,
                                    a.SalesRecordNumber,
                                    a.ItemId,a.ItemTitle,a.TotalPrice,
                                    dbo.ReplaceCustomLable(a.EbayUserId,a.CustomLable) as CustomLable,
                                    0 as yf,0 as tp,
                                    isnull(b.Delivery,'') as Delivery,
                                    a.Standard,a.OrderStatusId,
                                    a.OrderRetentionReson,a.IsPay,
                                    case when len(c.ParcelId) > 0 then '已发货' else '未发货' end as DeliveryStatus,
                                    case when len(f.OrderLineItemId) > 0 then '已评价' else '未评价' end  as FeedBackStatus,
                                    case when len(d.RefundId) > 0 then '已退款' else '未退款' end as RefundStatus,
                                    case when len(e.ReturnsOrderId) > 0 then '已退货' else '未退货' end as ReturnsStatus,
                                    a.IsReBuilderOrder,a.IsOutStock,a.SaleDate,a.PDate,a.MatchDate,a.PrintDate,a.PrintUserId,
                                    a.DeliveryDate,a.DeliveryUser,a.CancelDate,a.CancelUser,a.Mnote,a.UserId,a.BuyerFullName,
                                    a.BuyerEmail,a.BuyerAddress1,a.BuyerAddress2,a.BuyerCity,a.BuyerCounty,a.BuyerPostcode,
                                    a.BuyerCountry,a.BuyerPhoneNumber,a.PostageService,a.TransactionID,a.Memo,a.BuyerId,
                                    a.BuyerName,a.AddressLine1,a.AddressLine2,a.City,a.County,a.PostalCode,a.Country,
                                    a.ContactPhoneNumber,a.MatchStatusId,a.ReBuilderReson,a.Quantity,a.SendQuantity,
                                    m.Listing,a.BeiZhu
                                    From Orders a
                                    Left Outer Join ExpressShippingMethods b on a.DeliveryId = b.id
                                    Left Outer Join ParcelOrder c on a.OrderId = c.OrderId And a.EbayUserId = c.EbayUserId 
                                    Left Outer Join Refund d On a.OrderId = d.OrderId And a.EbayUserId = d.EbayUserId 
                                    Left Outer Join ReturnsOrder e On a.OrderId = e.OrderId And a.EbayUserId = e.EbayUserId
                                    Left Outer Join EbayFeedBack f On a.OrderLineItemId = f.OrderLineItemId and a.EbayUserId = f.EbayUserId
                                    Left Outer Join CustomLableMapping m on dbo.ReplaceCustomLable(a.EbayUserId,a.CustomLable) = m.CustomerId
                                    Where a.OrderId = @OrderId And a.EbayUserId = @EbayUserId";
                            SqlParameter[] p ={
                                new SqlParameter("@OrderId",orderId),
                                new SqlParameter("@EbayUserId",ebayUserId)
                            };
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        }
                    }
                    break;
                case "1006"://获取PayPal明细
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            T_PPOrderTableAdapter ordersAdapter = new T_PPOrderTableAdapter();
                            tableSource = ordersAdapter.GetDataByOrderId(ebayUserId, orderId);
                        }
                    }
                    break;
                case "1007"://商品明细
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            //                                string cmdText = @"Select Orders.OrderLineItemId,Orders.EbayUserId,Orders.SalesRecordNumber,Orders.OrderId,Orders.OrderStatusId,Product.FitemId,Product.ProductId,Product.ProductSpecification,Product.ProductName,
                            //                                Sum(CustomerResolve.Quantity) As TotalQuantity,Product.SalesGroup,EbayCategory.CategoryName, avg(CustomerResolve.SalePrice) as SalePrice,
                            //                                Sum(Orders.Quantity) as SingleQuantity,isnull(v_wfh.sQty,0) as sQty,isnull(v_wfh.fQty,0) as fQty,v_wfh.FName,
                            //                                CustomerResolve.WarehouseId
                            //                                From Product 
                            //                                Left Outer Join CustomerResolve on Product.ProductId = CustomerResolve.ProductId
                            //                                Left Outer Join EbayCategory On Product.CategoryId = EbayCategory.CategoryId
                            //                                Left Outer Join Orders ON CustomerResolve.OrderLineItemId = Orders.OrderLineItemId And CustomerResolve.EbayUserId = Orders.EbayUserId
                            //                                Left Outer Join v_wfh On CustomerResolve.ProductId = v_wfh.ProductId And CustomerResolve.WarehouseId = v_wfh.FstockId
                            //                                Where Orders.EbayUserId = @EbayUserId And Orders.OrderId = @OrderId
                            //                                group by  Orders.OrderLineItemId,Orders.EbayUserId,Orders.OrderId,Orders.OrderStatusId,Product.FitemId,Product.ProductId,Product.ProductSpecification,CustomerResolve.WarehouseId
                            //                                ,Product.ProductName,Product.SalesGroup,EbayCategory.CategoryName,v_wfh.sQty,v_wfh.fQty,v_wfh.FName,Orders.SalesRecordNumber";
                            string cmdText = @"Select Orders.OrderLineItemId,Orders.EbayUserId,Orders.SalesRecordNumber,Orders.OrderId,Orders.OrderStatusId
                                                            ,Product.FitemId,Product.FNumber  as ProductId,Product.FModel  as ProductSpecification,Product.FName  as ProductName,
                                                            Sum(CustomerResolve.Quantity) As TotalQuantity,Product.F_128  as SalesGroup,EbayCategory.CategoryName, avg(CustomerResolve.SalePrice) as SalePrice,
                                                            Sum(Orders.Quantity) as SingleQuantity,isnull(v_wfh.sQty,0) as sQty,isnull(v_wfh.fQty,0) as fQty,v_wfh.FName,
                                                            CustomerResolve.WarehouseId
                                                    From [AIS2011120420456].dbo.t_ICItem  as  Product 
                                                            Left Outer Join CustomerResolve on Product.FNumber = CustomerResolve.ProductId
                                                            Left Outer Join EbayCategory On Product.FComCategoryID = EbayCategory.CategoryId
                                                            Left Outer Join Orders ON CustomerResolve.OrderLineItemId = Orders.OrderLineItemId And CustomerResolve.EbayUserId = Orders.EbayUserId
                                                            Left Outer Join v_wfh On CustomerResolve.ProductId = v_wfh.ProductId And CustomerResolve.WarehouseId = v_wfh.FstockId
                                                    Where Orders.EbayUserId = @EbayUserId And Orders.OrderId = @OrderId
                                                     group by  Orders.OrderLineItemId,Orders.EbayUserId,Orders.OrderId,Orders.OrderStatusId,Product.FitemId,Product.FNumber,Product.FModel,CustomerResolve.WarehouseId
                                                            ,Product.FName,Product.F_128,EbayCategory.CategoryName,v_wfh.sQty,v_wfh.fQty,v_wfh.FName,Orders.SalesRecordNumber";
                            SqlParameter[] p ={
                                new SqlParameter("@EbayUserId",SqlDbType.VarChar),
                                new SqlParameter("@OrderId",SqlDbType.VarChar)
                            };
                            p[0].Value = ebayUserId;
                            p[1].Value = orderId;
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        }
                    }
                    break;
                case "1008"://替换记录查询
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            T_ProductReplaceContextTableAdapter productReplaceAdapter = new T_ProductReplaceContextTableAdapter();
                            tableSource = productReplaceAdapter.GetData(orderId, ebayUserId);
                        }
                    }
                    break;
                case "1009"://显示关联
                    {
                        string Where = " Orders.OrderStatusId <> 7  And Orders.OrderStatusId<> 8";
                        string ebayUserId = Request["ebayUserId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string buyerId = Request["buyerId"];
                        string buyerName = Request["BuyerFullName"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " Orders.EbayUserId = '" + ebayUserId + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 30);
                            timeTo = WebUtility.InputText(timeTo, 30);

                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += "  Orders.Mtime >= '" + timeFrom + "' AND Orders.Mtime <= '" + timeTo + "'";
                        }
                        if (!string.IsNullOrEmpty(buyerId)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Orders.UserId = '" + buyerId + "'";
                        }

                        if (!string.IsNullOrEmpty(buyerName)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " Orders.BuyerFullName = '" + buyerName + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                "Orders",
                                                "OrderLineItemId,UserId,BuyerFullName,BuyerEmail,Quantity,TotalPrice",
                                                "OrderId asc ",
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "1010"://解析商品明细
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            T_CustomerResolveContextTableAdapter cAdapter = new T_CustomerResolveContextTableAdapter();
                            tableSource = cAdapter.GetData(orderId, ebayUserId);
                        }
                    }
                    break;
                case "1011": {
                    string orderId = Request["OrderId"];
                    string ebayUserId = Request["ebayUserId"];
                    if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                        T_RefundContextTableAdapter rAdapter = new T_RefundContextTableAdapter();
                        tableSource = rAdapter.GetData(orderId, ebayUserId);
                    }
                }
                    break;
                case "1021": {
                    string orderId = Request["OrderId"];
                    string ebayUserId = Request["ebayUserId"];
                    string ot = Request["oType"];
                    if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                        //T_ParcelOrderTableAdapter adapter = new T_ParcelOrderTableAdapter();
                        //tableSource = adapter.GetDataByOrderId(orderId, ebayUserId, Convert.ToInt32(ot));
                        T_ParcelPrintTableAdapter adapter = new T_ParcelPrintTableAdapter();
                        tableSource = adapter.GetDataByOrderId(orderId, ebayUserId);
                    }
                }
                    break;
                case "1012"://发货单信息
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        string ot = Request["oType"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            string cmdText = "select OrderId,NewOrderId,EbayUserId,Mtime,Muser From Orders where NewOrderId  = @OrderId and EbayUserId = @EbayUserId";

                            SqlParameter[] p = { 
                                new SqlParameter("@OrderId",SqlDbType.VarChar),
                                new SqlParameter("@EbayUserId",SqlDbType.VarChar)
                            };
                            p[0].Value = orderId;
                            p[1].Value = ebayUserId;
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        }
                    }
                    break;
                case "1013"://退货信息
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            ebay.Dal.CenterDB_OrderTableAdapters.T_ReturnsOrderTableAdapter rAdapter = new ebay.Dal.CenterDB_OrderTableAdapters.T_ReturnsOrderTableAdapter();
                            tableSource = rAdapter.GetDataByOrderId(orderId, ebayUserId);
                        }
                    }
                    break;
                case "1014": //未匹配的Order
                    {
                        //string Where = " EbaySelling.SellingStatus = 1";
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string sellingStatus = Request["SellingStatus"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string orderId = Request["orderId"];
                        string BuyerId = Request["BuyerId"];
                        string BuyerName = Request["BuyerName"];
                        string buyerEmail = Request["buyerEmail"];
                        string recNum = Request["recNum"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " e.EbayUserId = '" + ebayUserId + "'";
                        }

                        if (!string.IsNullOrEmpty(sellingStatus.Trim())) {
                            sellingStatus = WebUtility.InputText(sellingStatus, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " e.SellingStatus = '" + sellingStatus + "'";
                        }

                        if (!string.IsNullOrEmpty(BuyerId.Trim())) {
                            BuyerId = WebUtility.InputText(BuyerId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " e.UserId = '" + BuyerId + "'";
                        }
                        if (!string.IsNullOrEmpty(BuyerName.Trim())) {
                            BuyerName = WebUtility.InputText(BuyerName, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " e.BuyerFullName = '" + BuyerName + "'";
                        }
                        if (!string.IsNullOrEmpty(buyerEmail.Trim())) {
                            BuyerName = WebUtility.InputText(buyerEmail, 255);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " e.BuyerEmail = '" + buyerEmail + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 30);
                            timeTo = WebUtility.InputText(timeTo, 30);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " CONVERT(varchar(19),e.ImportDate,21) >= '" + timeFrom + "' AND CONVERT(varchar(19),e.ImportDate,21) <= '" + timeTo + "'";
                            //Where += " EbaySelling.ImportDate >= '" + timeFrom + "' AND EbaySelling.ImportDate <= '" + timeTo + "'";
                        }
                        if (!string.IsNullOrEmpty(orderId.Trim())) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " e.OrderId = '" + orderId + "'";
                        }

                        if (!string.IsNullOrEmpty(recNum.Trim())) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " e.OrderSalesRecordNumber = '" + recNum + "'";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetCommonData(
                                                      "EbaySelling e LEFT JOIN Orders o ON e.eBayUserId = o.eBayUserId AND e.OrderLineItemId = o.OrderLineItemId",
                                                      "",
                                                      "e.EbayUserId, e.OrderId, e.UserId, e.BuyerFullName,Sum(e.Quantity) as Quantity,Avg(e.SalePrice) as SalePrice,Sum(e.TotalPrice) as TotalSalePrice, MAX(o.PaymentOrRefundAmount) AS PaymentOrRefundAmount, e.BuyerEmail, e.BuyerAddress1, e.BuyerAddress2, e.BuyerCity, e.BuyerPostcode, e.BuyerCountry, e.PayPalTransactionID, e.SellingStatus, e.OrderSalesRecordNumber, e.PostageAndPackaging",
                                                      string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                      string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                      Where,
                                                      "e.EbayUserId, e.OrderId, e.UserId, e.BuyerFullName, e.BuyerEmail, e.BuyerAddress1, e.BuyerAddress2, e.BuyerCity, e.BuyerPostcode, e.BuyerCountry, e.PayPalTransactionID, e.SellingStatus, e.OrderSalesRecordNumber, e.PostageAndPackaging",
                                                      "e." + sortName + " " + sortOrder,
                                                      ref rowCount);
                    }
                    break;
                case "1015": //未匹配的PayPal
                    {
                        string Where = "";
                        string ebayUserId = Request["ebayUserId"];
                        string StatusId = Request["StatusId"];
                        string timeFrom = Request["timeFrom"];
                        string timeTo = Request["timeTo"];
                        string transId = Request["transId"];
                        string BuyerId = Request["BuyerId"];
                        string BuyerName = Request["BuyerName"];
                        string flag = Request["flag"];
                        string FromEmailAddress = Request["FromEmailAddress"];
                        string ToEmailAddress = Request["ToEmailAddress"];
                        if (!string.IsNullOrEmpty(ebayUserId.Trim())) {
                            ebayUserId = WebUtility.InputText(ebayUserId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.EbayUserId = '" + ebayUserId + "'";
                        }

                        if (!string.IsNullOrEmpty(StatusId.Trim())) {
                            StatusId = WebUtility.InputText(StatusId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.StatusId = '" + StatusId + "'";
                        }

                        if (!string.IsNullOrEmpty(BuyerId.Trim())) {
                            BuyerId = WebUtility.InputText(BuyerId, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.BuyerId = '" + BuyerId + "'";
                        }
                        if (!string.IsNullOrEmpty(BuyerName.Trim())) {
                            BuyerName = WebUtility.InputText(BuyerName, 80);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.Name = '" + BuyerName + "'";
                        }
                        if (!string.IsNullOrEmpty(FromEmailAddress.Trim())) {
                            BuyerName = WebUtility.InputText(FromEmailAddress, 255);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.FromEmailAddress = '" + FromEmailAddress + "'";
                        }
                        if (!string.IsNullOrEmpty(ToEmailAddress.Trim())) {
                            BuyerName = WebUtility.InputText(ToEmailAddress, 255);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.ToEmailAddress = '" + ToEmailAddress + "'";
                        }
                        if (!string.IsNullOrEmpty(timeFrom) && !string.IsNullOrEmpty(timeTo)) {
                            timeFrom = WebUtility.InputText(timeFrom, 30);
                            timeTo = WebUtility.InputText(timeTo, 30);
                            if (Where.Length > 0) {
                                Where += " And";
                            }
                            Where += " PPOrder.ImportDate >= '" + timeFrom + "' AND PPOrder.ImportDate <= '" + timeTo + "'";
                        }
                        if (!string.IsNullOrEmpty(transId)) {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PPOrder.TransactionId = '" + transId + "'";
                        }

                        if (flag == "1") {
                            if (Where.Length > 0)
                                Where += " And";
                            Where += " PPInfoCol.CanMatch = 'Y' AND PPOrder.StatusId = 1";
                        }

                        PPOrder pp = new PPOrder();
                        string outTable = pp.GetQueryInfo("PPOrder", "PPInfoCol");
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                @"PPOrder Left Outer Join PPInfoCol  On " + outTable,
                                                " PPOrder.EbayUserId, PPOrder.TransactionId,"
                                                + "IsNull(PPInfoCol.CategoryName,'') As CategoryName, PPOrder.CreateDateTime, PPOrder.TimeZone, PPOrder.Name, "
                                                + "PPOrder.Type, PPOrder.Status, PPOrder.Subject, PPOrder.Currency, PPOrder.Gross, PPOrder.Fee, PPOrder.Net, "
                                                + "PPOrder.Reserve, PPOrder.Note, PPOrder.FromEmailAddress, PPOrder.ToEmailAddress, PPOrder.PaymentType, "
                                                + "PPOrder.CounterpartyStatus, PPOrder.PostalAddress, PPOrder.AddressStatus, PPOrder.ItemTitle, PPOrder.ItemID, "
                                                + "PPOrder.PostageandPackingAmount, PPOrder.InsuranceAmount, PPOrder.VAT, PPOrder.Option1Name, "
                                                + "PPOrder.Option1Value, PPOrder.Option2Name, PPOrder.Option2Value, PPOrder.AuctionSite, PPOrder.BuyerID, "
                                                + "PPOrder.ItemURL, PPOrder.ClosingDate, PPOrder.ReferenceTxnID, PPOrder.InvoiceNumber, "
                                                + "PPOrder.SubscriptionNumber, PPOrder.CustomNumber, PPOrder.ReceiptID, PPOrder.Balance, PPOrder.AddressLine1, "
                                                + "PPOrder.AddressLine2, PPOrder.City, PPOrder.County, PPOrder.PostalCode, PPOrder.Country, "
                                                + "PPOrder.ContactPhoneNumber, PPOrder.BalanceImpact, PPOrder.StatusId, PPOrder.ImportDate, "
                                                + "PPOrder.MatchDate",
                                                sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "1016": //报表部分BadProductReport
                    {
                        //ebay.Dal.Report report = new Report();
                        //tableSource = report.GetData();
                    }
                    break;
                case "1017"://ebayfee统计
                    {
                        //ebay.Dal.Report report = new Report();
                        //DataSet ds = report.GetEbayFee();
                        //tableSource = ds.Tables[0];
                    }
                    break;
                case "1018"://获取商品明细
                    {
                        string keyWord = Request["pq"];
                        if (!string.IsNullOrEmpty(keyWord)) {
                            //                                string cmdText = @"Select Top 10 UserCode,
                            //                                case when len(ProductName) > 30 then LEFT(ProductName,30) + '...' else ProductName end as ProductName,
                            //                                ISNULL(v_wfh.FQty,0) - ISNULL(v_wfh.sQty,0)  as Qty
                            //                                From Product
                            //                                left outer join StockMapping m on Product.DeliveryWarehouseId = m.WareHouseId
                            //                                left outer join v_wfh on Product.FitemId = v_wfh.FitemId Where UserCode Like  @UserCode + '%' and v_wfh.FStockID = m.FStockId";
                            String cmdText = @"SELECT TOP 10 UserCode,
      CASE WHEN LEN(ProductName) > 30 THEN LEFT(ProductName,30) + '...' ELSE ProductName END AS ProductName
    FROM Product
      LEFT OUTER JOIN StockMapping m ON Product.DeliveryWarehouseId = m.WareHouseId
    WHERE UserCode LIKE  @UserCode + '%'";
                            SqlParameter[] p = {
                                new SqlParameter("@UserCode", SqlDbType.VarChar)
                            };
                            p[0].Value = keyWord;
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        } else {
                            tableSource = null;
                        }
                    }
                    break;
                case "1019"://获取商品编码
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        string orderlineitemId = Request["oitmeId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId) && !string.IsNullOrEmpty(orderlineitemId)) {
                            T_CustomerResolveContextTableAdapter cAdapter = new T_CustomerResolveContextTableAdapter();
                            tableSource = cAdapter.GetDataByOrderLineItemId(orderId, ebayUserId, orderlineitemId);
                        }
                    }
                    break;
                case "1020"://重发订单商品明细
                    {
                        string cmdText = @"SELECT CustomerResolve.EbayUserId,
                                                    CustomerResolve.ProductId,p.ProductName,p.ProductSpecification,
                                                    MAX(CustomerResolve.CustomerLable) AS CustomerLable,
                                                    0 as Qty,
                                                    Sum(CustomerResolve.Quantity) as Quantity,
                                                    avg(CustomerResolve.SalePrice) as SalePrice,
                                                    avg(CustomerResolve.ItemCost) as ItemCost,
                                                    avg(CustomerResolve.TransactionFees) as TransactionFees,
                                                    avg(CustomerResolve.PayFee) as PayFee,
                                                    avg(CustomerResolve.TheoryPostAge) as TheoryPostAge,
                                                    avg(CustomerResolve.ActualPostage) as ActualPostage,
                                                    avg(CustomerResolve.PackageFee) as PackageFee,
                                                    avg(CustomerResolve.RefundLoss) as RefundLoss
                                                    ,CustomerResolve.Rate,CustomerResolve.WarehouseId
                                                    ,vw.[SQty],vw.[FQty]
                                                FROM CustomerResolve
                                                    inner join Orders on CustomerResolve.OrderLineItemId = Orders.OrderLineItemId
                                                    left outer join Product p on p.ProductId = CustomerResolve.ProductId
                                                        and CustomerResolve.EbayUserId = Orders.EbayUserId
                                                    left join [CenterDB].[dbo].[v_wfh] as vw on CustomerResolve.ProductId=vw.[productid]
                                                where (Orders.OrderStatusId = 2 or Orders.OrderStatusId=5 or Orders.OrderStatusId=6 OR Orders.OrderStatusId=10) 
                                                    and Orders.EbayUserId = @EbayUserId 
                                                    And Orders.OrderId = @OrderId
                                                group by CustomerResolve.EbayUserId,Orders.OrderId,p.ProductName,p.ProductSpecification,
                                                CustomerResolve.ProductId,CustomerResolve.Rate,CustomerResolve.WarehouseId,vw.[SQty],vw.[FQty]";

                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            SqlParameter[] p ={
                                new SqlParameter("@EbayUserId",SqlDbType.VarChar),
                                new SqlParameter("@OrderId",SqlDbType.VarChar)
                            };
                            p[0].Value = ebayUserId;
                            p[1].Value = orderId;
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        }
                    }
                    break;
                case "1022"://退货单商品明细 2012-08-03
                    {
                        string cmdText = @"select r.ReturnsOrderId as ReturnsOrderId ,r.FitemId as FitemId,l.FQty as FQty,l.FPrice as FPrice,
                                                       l.FAmount as FAmount,l.ProductId as ProductId,l.ProductName as ProductName,l.ProductSpecification as ProductSpecification
                                               from ReturnsOrder r left join(
                                                     select t1.FBillNo,t1.FExplanation,t2.FItemID,t2.FQty,t2.FPrice,t2.FAmount,p.ProductId,p.ProductName,p.ProductSpecification                                           
                                                        from [AIS2011120420456].dbo.ICStockBill as t1
                                                        inner join [AIS2011120420456].dbo.ICStockBillEntry as t2 on t1.FInterID=t2.FInterID                                                       
                                                        left join [CenterDB].dbo.Product p on t2.FItemID =p.FitemId                                                             	
                                                        where t1.FTranType = 21 and  t1.FROB = -1
                                                              and isnull(t1.FCheckerID,0) > 0 --已审核
                                                              and ISNULL(t1.FCancellation,0) = 0--未作废
                                                      )l
                                                     on l.FBillNo =r.ReturnsOrderId and r.FitemId=l.FItemID
                                               where r.ReturnsOrderId =@ReturnsOrderId and r.FitemId=@FitemId";
                        string ReturnsOrderId = Request["ReturnsOrderId"];
                        string FitemId = Request["FitemId"];
                        if (!string.IsNullOrEmpty(ReturnsOrderId) && int.Parse(FitemId) != 0) {
                            SqlParameter[] p ={
                                new SqlParameter("@ReturnsOrderId",SqlDbType.VarChar),
                                new SqlParameter("@FitemId",SqlDbType.Int)
                            };
                            p[0].Value = ReturnsOrderId;
                            p[1].Value = FitemId;
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        }
                    }
                    break;
                case "1080": {
                    string OrderId = Request["OrderId"];
                    string Account = Request["Account"];
                    string beginDate = Request["beginDate"];
                    string endDate = Request["endDate"];
                    string Where = " [Mtime]>='" + beginDate + "' and  Mtime<='" + endDate + "' ";
                    if (!string.IsNullOrEmpty(OrderId.Trim())) {
                        OrderId = WebUtility.InputText(OrderId, 100);
                        if (Where.Length > 0)
                            Where += " And";
                        Where += "  [OrderSalesRecordNumber] LIKE '%" + OrderId + "%'";
                    }
                    if (!string.IsNullOrEmpty(Account.Trim())) {
                        Account = WebUtility.InputText(Account, 100);
                        if (Where.Length > 0)
                            Where += " And";
                        Where += " [Account]= '" + Account + "' ";
                    }
                    Pagination p = new Pagination();
                    tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                            string.IsNullOrEmpty(pageSize) ? 50 : int.Parse(pageSize),
                                            @" [CenterDB].[dbo].[OrdersChangeLog] as a",
                                            " [Account],[OrderLineItemId],[OrderSalesRecordNumber],[StatusName],[OrderRetentionReson],[Standard],[PDate],[MatchDate],[Memo],[Muser],[Mtime] ",
                                            "a." + sortName + " " + sortOrder,
                                            Where,
                                            ref maxPage,
                                            ref rowCount,
                                            ref description);
                }
                    break;
                case "1023": //库存一览表 2012-08-16
                    {
                        string Where = " a1.Wh_code in ('5552','5555','5556','5559','22380','22381','39756','5554','40735') ";
                        string pscation = Request["pscation"];
                        string sales = Request["sales"];
                        if (!string.IsNullOrEmpty(pscation.Trim())) {
                            pscation = WebUtility.InputText(pscation, 100);
                            if (Where.Length > 0)
                                Where += " And";
                            Where += "  ProductSpecification LIKE '" + pscation + "%'";
                        }
                        if (!string.IsNullOrEmpty(sales.Trim())) {
                            sales = WebUtility.InputText(sales, 100);
                            if (Where.Length > 0)
                                Where += " And";
                            //if (sales == "是")
                            //{
                            //    Where += " isnull(d.ProductId,'0') <> '0'";
                            //}
                            //else
                            //{
                            //    Where += " isnull(d.ProductId,'0') = '0'";
                            //}
                            Where += " c.FName= '" + sales + "' ";
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 50 : int.Parse(pageSize),
                                                //@" vw_Inventory as a left outer join dbo.vw_OnLine as d on a.ProductId= d.ProductId left outer join Product p on p.ProductId= d.ProductId ",
                                                //  " a.FStockID as FStockID, a.FName as FName, a.ProductId as ProductId, a.ProductName as ProductName,"
                                                //   + "a.FNumber as FNumber, a.sQty as sQty, a.FQty as FQty, 0 as Cost, p.ProductSpecification as ProductSpecification,"
                                                //   + "case when isnull(d.ProductId,'0') <> '0'  then '是' else '否' end as Sales",
                                                @" [Transfer].dbo.K3_Stock as a1
                                                        left join CenterDB.dbo.Product as a
                                                        on a1.Prod_code=a.UserCode
                                                        left join AIS2011120420456.dbo.t_stock as c
                                                        on a1.Wh_code=c.FitemId
                                                        left join CenterDB.dbo.v_wfh as d
                                                        on d.productid=a1.Fnumber and a1.Wh_code=d.FStockId 
                                                        inner join AIS2011120420456.dbo.t_ICItemDesign as icd on icd.FItemID=a1.FItemID",
                                                " a1.Wh_code as FStockID,c.FName as FName,a1.Fnumber as ProductId,a.ProductName as ProductName,case when icd.FGrossWeight=0 then cast(icd.FNetWeight as decimal(28,2)) else cast(icd.FGrossWeight as decimal(28,2)) end as Weight,"
                                                + "'' as FNumber,ISNULL(d.SQty,0) as sQty,a1.Quantity as FQty,a1.cost as Cost,a1.Prod_code as ProductSpecification,"
                                                + "'是' as Sales",
                                                "a." + sortName + " " + sortOrder,
                                                Where,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "1024"://添加商品信息
                    {
                        string orderId = Request["OrderId"];
                        string ebayUserId = Request["ebayUserId"];
                        //string orderId = HttpUtility.UrlDecode(Request["OrderId"]);
                        //string orderIdx = HttpUtility.UrlDecode(Request.QueryString["OrderId"]);
                        //string ebayUserId = HttpUtility.UrlDecode(Request["ebayUserId"]);
                        string cmdText = @"select OrderLineItemId,EbayUserId,OrderId,Standard
	                                             from Orders
                                               Where Orders.OrderId =@OrderId And Orders.EbayUserId =@EbayUserId";
                        if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                            SqlParameter[] p ={
                                new SqlParameter("@OrderId",SqlDbType.VarChar),
                                new SqlParameter("@EbayUserId",SqlDbType.VarChar)
                            };
                            p[0].Value = orderId;
                            p[1].Value = ebayUserId;
                            tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                        }
                    }
                    break;
                case "1025": {
                    string orderId = Request["OrderId"];
                    string ebayUserId = Request["ebayUserId"];
                    string cmdText = @"SELECT o.EbayUserId, o.OrderLineItemId, r.ProductId,p.FName as ProductName ,p.FModel as ProductSpecification,0 as Qty,Sum(r.Quantity) as Quantity,MAX(o.PaymentOrRefundAmount) AS RefundAmount
                                                            FROM CustomerResolve r 
                                                                INNER JOIN Orders o ON r.OrderLineItemId = o.OrderLineItemId 
                                                                LEFT OUTER JOIN  [AIS2011120420456] .dbo.t_ICItemCore p on p.FNumber = r.ProductId AND r.EbayUserId = o.EbayUserId
                                                            WHERE o.EbayUserId = @EbayUserId And o.OrderId = @OrderId AND o.NewOrderId = ''
                                                            GROUP BY o.EbayUserId, o.OrderLineItemId, o.OrderId,p.FName,p.FModel, r.ProductId";
                    if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId)) {
                        SqlParameter[] p ={
                            new SqlParameter("@OrderId",SqlDbType.VarChar),
                            new SqlParameter("@EbayUserId",SqlDbType.VarChar)
                        };
                        p[0].Value = orderId;
                        p[1].Value = ebayUserId;
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                    }
                }
                    break;
                case "8001": {
                    String orderID = Request["OrderID"];
                    String eBayUserID = Request["eBayUserID"];
                    String sqlString = @"SELECT o.ItemTitle,o.Quantity,o.SalePrice AS Price,o.ItemId AS ItemID,a.Listing FROM Orders o LEFT JOIN eBayActiveListing a ON o.ItemID=a.ItemID WHERE OrderID=@OrderID AND o.eBayUserID=@eBayUserID";

                    if (!String.IsNullOrEmpty(eBayUserID) && !String.IsNullOrEmpty(orderID)) {
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                            new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = orderID }
                        };

                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    }
                }
                    break;
                case "8002": {
                    String orderID = Request["OrderID"];
                    String eBayUserID = Request["eBayUserID"];
                    String sqlString = @"SELECT DISTINCT o.PayPalTransactionID AS TransactionID,o.PaidonDate,CAST(p.Gross AS DECIMAL(10,2)) AS Amount,CAST(p.Fee AS DECIMAL(10,2)) AS PayPalFee,CAST(Net AS DECIMAL(10,2)) AS Gross FROM Orders o JOIN PPOrder p ON o.PayPalTransactionID=p.TransactionID WHERE o.eBayUserID=@eBayUserID AND o.OrderID=@OrderID";

                    if (!String.IsNullOrEmpty(eBayUserID) && !String.IsNullOrEmpty(orderID)) {
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                            new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = orderID }
                        };

                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    }
                }
                    break;
                      // get mail's dispute from database
                case "8003": {
                    String eBayUserID = Request["eBayUserID"];
                    String treeID = Request["TreeID"];
                    Boolean showHistory = Request["Show"] == "true" ? true : false;
                    ebay.BLL.DisputeManage manage = new ebay.BLL.DisputeManage();

                    tableSource = manage.GetPaginationDistpue(
                        eBayUserID,
                        treeID,
                        showHistory,
                        string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                        string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                        sortName,
                        sortOrder,
                        ref maxPage,
                        ref rowCount,
                        ref description
                        );
                }
                    break;
                case "8004": {
                        String eBayUserID = Request["eBayUserID"];
                        String item = Request["item"];
                        String text = Request["text"];
                        ebay.BLL.DisputeManage manage = new ebay.BLL.DisputeManage();

                        switch (item) {
                            case "OrderID": {
                                    tableSource = manage.GetDisputeByOrderSaleRecordNo(eBayUserID, text, string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                        string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize), sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                                }
                                break;
                            case "ProdCode": {
                                    tableSource = manage.GetDisputeByProdCode(eBayUserID, text, string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                        string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize), sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                                }
                                break;
                            case "CaseID": {
                                    tableSource = manage.GetDisputeByCaseID(eBayUserID, text, string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                          string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize), sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                                }
                                break;
                            case "CustomerID": {
                                    tableSource = manage.GetDisputeByCustomerID(eBayUserID, text, string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                          string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize), sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                                }
                                break;
                            case "CustomerName": {
                                    tableSource = manage.GetDisputeByCustomerName(eBayUserID, text, string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                          string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize), sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                case "8005": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];
                    if (String.IsNullOrEmpty(eBayUserID) || String.IsNullOrEmpty(orderID))
                        break;

                    //String sqlString = "SELECT d.DisputeID,o.ItemTitle AS Title,d.OtherPartyName AS BuyerID,o.ItemID,d.DisputeModifiedTime AS DisputeDate,d.DisputeState AS Status FROM eBayDispute d JOIN eBaySelling o ON d.OrderLineItemID=o.OrderLineItemID WHERE o.OrderID=@OrderID AND o.eBayUserID=@eBayUserID";
                    String sqlString = "SELECT c.CaseID,c.ItemTitle AS Title,c.OtherPartyID AS BuyerID,c.ItemID,c.CreationDate AS DisputeDate,c.CaseStatusValue AS Status FROM eBayUserCase c JOIN eBaySelling o ON c.ItemID=o.ItemID AND c.TransactionID=o.TransactionID WHERE o.OrderID=@OrderID AND o.eBayUserID=@eBayUserID";
                    SqlParameter[] parameters = new SqlParameter[] {
                        new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                        new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = orderID }
                    };

                    tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                }
                    break;
                case "8006": {
                    String eBayUserID = Request["ebayuserid"];
                    String disputeID = Request["disputeid"];
                    if (String.IsNullOrEmpty(eBayUserID) || String.IsNullOrEmpty(disputeID))
                        break;

                    String sqlString = "SELECT m.DisputeID,m.MessageCreationTime AS Date,m.MessageSource AS Role,m.MessageText AS Message FROM eBayDisputeMessage m WHERE m.eBayUserID=@eBayUserID AND m.DisputeID=@DisputeID";
                    SqlParameter[] parameters = new SqlParameter[] {
                        new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                        new SqlParameter() { ParameterName = "@DisputeID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = disputeID }
                    };

                    tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                }
                    break;
                case "8007": {
                    String eBayUserID = Request["eBayUserID"];
                    String treeID = Request["TreeID"];
                    Boolean showHistory = Convert.ToBoolean(Request["Show"]);
                    ebay.BLL.FeedbackManage manage = new ebay.BLL.FeedbackManage();

                    tableSource = manage.GetFeedbackSource(
                                                    eBayUserID,
                                                    treeID,
                                                    showHistory,
                                                    String.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                    String.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                    sortName,
                                                    sortOrder,
                                                    ref maxPage,
                                                    ref rowCount,
                                                    ref description
                                                    );
                    //switch (folderID) {
                    //    // 未回复负评
                    //  case "4096": {
                    //      tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //      tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //      tableWhere = String.Format(
                    //                                 "f.eBayUserID='{0}' AND f.CommentType='Negative' AND f.HasResponse=0",
                    //                                 eBayUserID
                    //                                 );
                    //  }
                    //      break;
                    //      // 常规跟进
                    //  case "4608": {
                    //      tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //      tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //      tableWhere = String.Format(
                    //                                 "f.eBayUserID='{0}' AND f.CommentType='Negative' AND t.[Level]='常规跟进' AND f.HasReject=0 AND DATEADD(DAY,7,LastReplyDate)<GETDATE() AND o.BuyerCountry IN ('IE','GB','Ireland','United Kingdom')",
                    //                                 eBayUserID
                    //                                 );
                    //  }
                    //      break;
                    //      // 高级跟进
                    //  case "4864": {

                    //  }
                    //      break;
                    //      // 高级跟进 负评
                    //  case "4880": {
                    //      tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //      tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //      tableWhere = String.Format(
                    //                                 "f.eBayUserID='{0}' AND f.CommentType='Negative' AND t.[Level]='高级跟进' AND f.HasReject=0 AND (LastReplyDate IS NULL OR LastReplyDate<CONVERT(VARCHAR(10),GETDATE(),120)) AND o.BuyerCountry in ('IE','GB','Ireland','United Kingdom')",
                    //                                 eBayUserID
                    //                                 );
                    //  }
                    //      break;
                    //      // 高级跟进 中评
                    //  case "4896": {
                    //      tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //      tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //      tableWhere = String.Format(
                    //                                 "f.eBayUserID='{0}' AND f.CommentType='Neutral' AND t.[Level]='高级跟进' AND f.HasReject=0 AND (LastReplyDate IS NULL OR LastReplyDate<CONVERT(VARCHAR(10),GETDATE(),120)) AND o.BuyerCountry in ('IE','GB','Ireland','United Kingdom')",
                    //                                 eBayUserID
                    //                                 );
                    //  }
                    //      break;
                    //      // 负评
                    //  case "5120": {
                    //          tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //          tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //          tableWhere = String.Format(
                    //                                     "f.eBayUserID='{0}' AND f.CommentType='Negative' AND f.HasResponse=1 AND (t.[Level]<>'常规跟进' or f.HasReject=1 or DATEADD(DAY,7,LastReplyDate)>GETDATE() OR o.BuyerCountry NOT IN ('IE','GB','Ireland','United Kingdom')) AND (t.[Level]<>'高级跟进' OR f.HasReject=1 OR LastReplyDate>CONVERT(VARCHAR(10),GETDATE(),120) OR o.BuyerCountry NOT IN ('IE','GB','Ireland','United Kingdom'))",
                    //                                     eBayUserID
                    //                                     );
                    //      }
                    //      break;
                    //      // 中评
                    //  case "5376": {
                    //          tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //          tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //          tableWhere = String.Format(
                    //                                     "f.eBayUserID='{0}' AND f.CommentType='Neutral' AND (t.[Level]<>'高级跟进' OR f.HasReject=1 OR LastReplyDate>=CONVERT(VARCHAR(10),GETDATE(),120) OR o.BuyerCountry NOT IN ('IE','GB','Ireland','United Kingdom'))",
                    //                                     eBayUserID
                    //                                     );
                    //      }
                    //      break;
                    //      // 正评
                    //  case "5632": {
                    //      tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //      tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //      tableWhere = String.Format(
                    //                                 "f.eBayUserID='{0}' AND f.CommentType='Positive'",
                    //                                 eBayUserID
                    //                                 );
                    //  }
                    //      break;
                    //      // 已撤销负评
                    //  case "5888": {
                    //      tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                    //      tableFrom = "eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID LEFT JOIN eBayFeedbackFollowType t ON f.FollowLevel=t.Type";
                    //      tableWhere = String.Format(
                    //                                 "f.eBayUserID='{0}' AND f.CommentType='Revised'",
                    //                                 eBayUserID
                    //                                 );
                    //  }
                    //      break;
                    //}

                    //tableWhere += bShow ? "" : " AND f.CommentTime BETWEEN DATEADD(MONTH,-2,CONVERT(VARCHAR(10),GETDATE(),120)) AND DATEADD(DAY,1,CONVERT(VARCHAR(10),GETDATE(),120))";
                    //Pagination p = new Pagination();
                    //tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                    //                        string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                    //                        tableFrom,
                    //                        tableField,
                    //                        sortName + " " + sortOrder,
                    //                        tableWhere,
                    //                        ref maxPage,
                    //                        ref rowCount,
                    //                        ref description);
                }
                    break;
                case "8008": {
                        String eBayUserID = Request["ebayuserid"];
                        String searchType = Request["type"];
                        String searchText = Request["text"];
                        String dateType = Request["datetype"];
                        DateTime fromDate = Convert.ToDateTime(Request["from"]);
                        DateTime toDate = Convert.ToDateTime(Request["to"]);

                        String tableField = "f.FeedbackID,f.CommentingUser AS BuyerID,f.CommentType,f.CommentTime,f.CommentText,o.ItemID,o.OrderID,o.OrderSalesRecordNumber";
                        String tableFrom = "eBayFeedback f JOIN Orders o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID";
                        String tableWhere = "1=1 AND ";
                        switch (searchType) {
                            case "OrderID": {
                                    tableWhere += String.Format(
                                                                "o.eBayUserID='{0}' AND o.OrderSalesRecordNumber='{1}' ",
                                                                eBayUserID,
                                                                searchType
                                                                );
                                }
                                break;
                            case "CaseID": {
                                    tableWhere += String.Format(
                                                                "o.eBayUserID='{0}' AND f.FeedbackID='{1}' ",
                                                                eBayUserID,
                                                                searchType
                                                                );
                                }
                                break;
                            case "CustomerID": {
                                    tableWhere += String.Format(
                                                                "o.eBayUserID='{0}' AND f.UserID='{1}' ",
                                                                eBayUserID,
                                                                searchType
                                                                );
                                }
                                break;
                            case "CustomerName": {
                                    tableWhere += String.Format(
                                                                "o.eBayUserID='{0}' AND f.BuyerFullName='{1}' ",
                                                                eBayUserID,
                                                                searchType
                                                                );
                                }
                                break;
                        }
                        switch (dateType) {
                            case "feedbackdate":
                                tableWhere += String.Format(
                                                            "f.CommentTime BETWEEN '{0}' AND '{1}'",
                                                            fromDate,
                                                            toDate
                                                            );
                                break;
                            case "saledate":
                                tableWhere += String.Format(
                                                            "o.SaleDate BETWEEN '{0}' AND '{1}'",
                                                            fromDate,
                                                            toDate
                                                            );
                                break;
                            case "paidondate":
                                tableWhere += String.Format(
                                                            "o.PaidonDate BETWEEN '{0}' AND '{1}'",
                                                            fromDate,
                                                            toDate
                                                            );
                                break;
                            case "shippingdate":
                                tableWhere += String.Format(
                                                            "o.PDate BETWEEN '{0}' AND '{1}'",
                                                            fromDate,
                                                            toDate
                                                            );
                                break;
                        }
                        Pagination p = new Pagination();
                        tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                                string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                                tableFrom,
                                                tableField,
                                                sortName + " " + sortOrder,
                                                tableWhere,
                                                ref maxPage,
                                                ref rowCount,
                                                ref description);
                    }
                    break;
                case "8009": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];
                    String sqlString = "SELECT DISTINCT f.FeedbackID AS ID,f.CommentType AS Type,o.ItemTitle,o.ItemID,CommentText AS Message,CommentTime AS Date,f.OrderLineItemID,o.eBayUserID,o.OrderID FROM eBayFeedback f JOIN eBaySelling o ON f.eBayUserID=o.eBayUserID AND f.OrderLineItemID=o.OrderLineItemID WHERE o.eBayUserID=@eBayUserID AND o.OrderID=@OrderID";

                    SqlParameter[] parameters = new SqlParameter[] {
                        new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                        new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = orderID }
                    };

                    tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                }
                    break;
                case "8010": {
                    String eBayUserID = Request["ebayuserid"];
                    String feedbackID = Request["feedbackid"];

                    try {
                        String sqlString = "SELECT f.CommentTime AS Date,f.CommentingUser AS Username,f.CommentText AS Message FROM eBayFeedback f WHERE f.eBayUserID=@eBayUserID AND f.FeedbackID=@FeedbackID";
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.VarChar, Size = 80, Value = eBayUserID },
                            new SqlParameter() { ParameterName = "@FeedbackID", SqlDbType = SqlDbType.VarChar, Size = 20, Value = feedbackID }
                        };

                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    } catch (System.Exception ex) {
                        tableSource = GetMsgTable("1", "查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                case "8011": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];

                    try {
                        String sqlString = "SELECT DISTINCT p.OrderID,p.BuyerFullName AS BuyerName,p.parcel_id AS ParcelID,o.ReBuilderReson AS RebuildReason,p.BuyerAddress1+' '+p.BuyerAddress2 AS BuyerStreet,p.DispatchDate AS ShippingDate,o.Muser AS CreateUser,p.BuyerCity,p.my_PostageService AS PostageService,p.BuyerCountry,ISNULL(p.Memo,'RoyalMail') AS ShippingService,p.BuyerPostcode AS BuyerZipCode,n.No_plate AS TrackingNo,p.BuyerPhoneNumber,p.totalweight AS Weight,p.BuyerEmail,dbo.fn_CalcPostage('','','',0) AS Postage FROM Orders o JOIN ParcelPrint p ON o.eBayUserID=p.EbayUserID AND o.OrderLineItemId=p.OrderLineItemId LEFT JOIN ParcelPrintTrackingNumber n ON p.parcel_id=n.c_barcode WHERE o.eBayUserID=@eBayUserID AND o.OrderID LIKE @OrderID";
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                            new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 40, Value = orderID + "_%" }
                        };
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    } catch (System.Exception ex) {
                        tableSource = GetMsgTable("1", "查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                case "8012": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];

                    try {
                        String sqlString = "SELECT DISTINCT d.UserCode AS ProdCode,d.ProductName AS ProdName,r.Quantity FROM ParcelPrint p JOIN CustomerResolve r ON p.eBayUserID=r.eBayUserID AND p.OrderLineItemID=r.OrderLineItemID JOIN Product d ON r.ProductID=d.ProductID WHERE p.eBayUserID=@eBayUserID AND p.OrderID=@OrderID";
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                            new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 40, Value = orderID }
                        };
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    } catch (System.Exception ex) {
                        tableSource = GetMsgTable("1", "查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                case "8013": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];

                    try {
                        String sqlString = "SELECT DISTINCT r.RefundID,CAST(r.RefundAmount AS DECIMAl(10,2)) AS AMT,r.RefundDate AS Date,t.RefundType AS Reason,r.Muser AS MUser,r.Auser AS AUser,r.Mnote AS Comment FROM Refund r JOIN RefundType t ON r.RefundType=t.Id WHERE eBayUserID=@eBayUserID AND OrderID=@OrderID";
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                            new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = orderID }
                        };
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    } catch (System.Exception ex) {
                        tableSource = GetMsgTable("1", "查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                case "8014": {
                    try {
                        String sqlString = "SELECT DISTINCT ID, Type, [Level] FROM eBayFeedbackFollowType";
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, new SqlParameter[0]);
                    } catch (System.Exception ex) {
                        Log.WriteLog("查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                case "8015": {
                    try {
                        String sqlString = "SELECT DISTINCT ID,Username,Signature FROM MailUsers u";
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, new SqlParameter[0]);
                    } catch (System.Exception ex) {
                        Log.WriteLog("查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                case "8016": {
                    String eBayUserID = Request["eBayUserID"];
                    String treeID = Request["TreeID"];
                    Boolean show = Request["show"] == "true" ? true : false;
                    ebay.Dal.MessageService msg = new ebay.Dal.MessageService();

                    tableSource = msg.QueryMessageByTreeID(eBayUserID, treeID, show, pageNumber, pageSize, sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                    }
                    break;
                case "8017": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];
                    ebay.Dal.MessageService msg = new ebay.Dal.MessageService();

                    try {
                        tableSource = msg.QueryMessageByOrderID(eBayUserID, orderID);
                    } catch (System.Exception ex) {
                        tableSource = GetMsgTable("1", "查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                    // Shipment's product table query
                case "8018": {
                    String eBayUserID = Request["ebayuserid"];
                    String orderID = Request["orderid"];
                    String sqlString = "SELECT DISTINCT o.eBayUserID,o.OrderLineItemID,o.OrderStatusId,p.ProductID,p.UserCode,p.ProductName,r.Quantity,w.FQty,w.SQty,r.WarehouseId FROM Orders o JOIN CustomerResolve r ON o.eBayUserID=r.eBayUserID AND o.OrderLineItemID=r.OrderLineItemID JOIN Product p ON r.ProductId = p.ProductId LEFT JOIN v_wfh w ON p.ProductID=w.ProductID WHERE o.eBayUserID=@eBayUserID AND o.OrderID=@OrderID";
                    SqlParameter[] parameters = new SqlParameter[] {
                        new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID },
                        new SqlParameter() { ParameterName = "@OrderID", SqlDbType = SqlDbType.NVarChar, Size = 30 , Value = orderID }
                    };

                    try {
                        tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                    } catch (System.Exception ex) {
                        tableSource = GetMsgTable("1", "查询出错,错误代码: " + ex.Message + "...");
                    }
                }
                    break;
                    // Query message by order id, case id...
                case "8019": {
                    String eBayUserID = Request["ebayuserid"];
                    String item = Request["item"];
                    String text = Request["text"];
                    MessageService msg = new MessageService();
                    tableSource = msg.QueryMessage(eBayUserID, item, text, pageNumber, pageSize, sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                }
                    break;
                    // Query repsonse
                case "8020": {
                    String eBayUserID = Request["eBayUserID"];
                    int treeID = Convert.ToInt32(Request["TreeID"]);
                    ebay.Dal.Response response = new ebay.Dal.Response();

                    tableSource = response.QueryResponse(eBayUserID, treeID, pageNumber, pageSize, sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                }
                    break;
                    // Query message by recipient id...
                case "8021": {
                    String eBayUserID = Request["ebayuserid"];
                    String item = Request["item"];
                    String text = Request["text"];
                    ebay.Dal.Response response = new ebay.Dal.Response();
                    tableSource = response.QueryResponse(eBayUserID, item, text, pageNumber, pageSize, sortName, sortOrder, ref maxPage, ref rowCount, ref description);
                }
                    break;
                case "8022": {
                    String eBayUserID = Request["ebayuserid"];
                    String msgID = Request["messageid"];
                    ebay.Dal.MessageService msg = new ebay.Dal.MessageService();

                    tableSource = msg.QueryMessageByMessageID(eBayUserID, msgID);
                }
                    break;
                case "8023": {
                    String sqlString = "SELECT ID,Name,Text AS Content FROM MessageTemplate";

                    tableSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, new SqlParameter[0]);
                }
                    break;
                    // Message 高级查询
                case "8024": {
                    String eBayUserID = Request["ebayuserid"];
                    String keyword = Request["keyword"];
                    String product = Request["product"];
                    String startdate = Request["startdate"];
                    String enddate = Request["enddate"];
                    String tableWhere = "1=1";
                    String tableFrom = "eBayMessage m";
                    String tableField = "m.MessageID,m.Sender,m.Subject,m.[Read],m.OrderID,m.OrderSalesRecordNumber,m.ReceiveDate,m.Flag";

                    if (!String.IsNullOrEmpty(keyword)) {
                        tableWhere += String.Format(
                                                    " AND m.Subject LIKE '%{0}%'",
                                                    keyword
                                                    );
                    }

                    if (!String.IsNullOrEmpty(product)) {
                        tableWhere += String.Format(
                                                    " AND p.ProductName LIKE '%{0}%'",
                                                    product
                                                    );
                        tableFrom += " JOIN eBaySelling o ON m.eBayUserID=o.eBayUserID AND m.OrderID=o.OrderID JOIN CustomerResolve r ON o.eBayUserID=r.eBayUserID AND o.OrderLineItemID=r.OrderLineItemID JOIN Product p ON r.ProductID=p.ProductID";
                    }

                    if (!String.IsNullOrEmpty(startdate)) {
                        tableWhere += String.Format(
                                                    " AND m.ReceiveDate>='{0}'",
                                                    keyword
                                                    );
                    }

                    if (!String.IsNullOrEmpty(enddate)) {
                        tableWhere += String.Format(
                                                    " AND m.ReceiveDate<='{0}'",
                                                    keyword
                                                    );
                    }

                    Pagination p = new Pagination();
                    tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                            string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                            tableFrom,
                                            tableField,
                                            sortName + " " + sortOrder,
                                            tableWhere,
                                            ref maxPage,
                                            ref rowCount,
                                            ref description);
                }
                    break;
                case "8025": {
                    String tableFrom = "KnowledgeBase k";
                    String tableField = "k.ID,k.ProductCode,k.Question,k.Answer,k.Keywords,k.ImportDate AS Date,k.AUser";

                    Pagination p = new Pagination();
                    tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                            string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                            tableFrom,
                                            tableField,
                                            sortName + " " + sortOrder,
                                            String.Empty,
                                            ref maxPage,
                                            ref rowCount,
                                            ref description);
                }
                    break;
                case "8026": {
                    String item = Request["item"];
                    String text = Request["text"];
                    String tableField = String.Empty;
                    String tableFrom = String.Empty;
                    String tableWhere = String.Empty;

                    tableField = "k.ID,k.ProductID,k.Question,k.Content,k.Keywords,k.ImportDate AS Date";

                    switch (item) {
                      case "ProductID": {
                          tableWhere = String.Format(
                                                     "k.ProductID='{0}'",
                                                     text
                                                     );
                          tableFrom = "KnowledgeBase k";
                      }
                          break;
                      case "ProductName": {
                          tableWhere = String.Format(
                                                     "p.ProductName LIKE '%{0}%'",
                                                     text
                                                     );
                          tableFrom = "KnowledgeBase k JOIN Product p ON k.ProductID=p.ProductID";
                      }
                          break;
                      case "Keyword": {
                          tableWhere = String.Format(
                                                     "d.Keyword LIKE '%{0}%'",
                                                     text
                                                     );
                          tableFrom = "KnowledgeBase k JOIN KnowledgeKeywordDetail d ON k.ID=d.KnowledgeID";
                      }
                          break;
                      case "Question": {
                          tableWhere = String.Format(
                                                     "k.Question LIKE '%{0}%'",
                                                     text
                                                     );
                          tableFrom = "KnowledgeBase k";
                      }
                          break;
                    }

                    Pagination p = new Pagination();
                    tableSource = p.GetData(string.IsNullOrEmpty(pageNumber) ? 1 : int.Parse(pageNumber),
                                            string.IsNullOrEmpty(pageSize) ? 10 : int.Parse(pageSize),
                                            tableFrom,
                                            tableField,
                                            sortName + " " + sortOrder,
                                            String.Empty,
                                            ref maxPage,
                                            ref rowCount,
                                            ref description);
                }
                    break;
                case "8027": {

                    }
                    break;
              }
              break;
#endregion

#region delete
          case "d":
              string Id = Request["id"];
              string Id2 = Request["id2"];
              switch (tableName) {
                case "01"://DownLoadLog
                    break;
                case "27"://users
                    {
                        try {
                            Users u = new Users();
                            if (u.DeleteUser(Id)) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;

                case "23"://ProgCategory
                    {
                        try {
                            T_ProgCategoryTableAdapter adapter = new T_ProgCategoryTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "18"://PayPalAccount
                    {
                        try {
                            T_PayPalAccountTableAdapter adapter = new T_PayPalAccountTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "03": //EbayAccount
                    {
                        try {
                            T_EbayAccountTableAdapter adapter = new T_EbayAccountTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "14": //EbayPaypalAccountRelation
                    {
                        try {
                            T_EbayPaypalAccountRelationTableAdapter adapter = new T_EbayPaypalAccountRelationTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "21"://PPInfoCol
                    {
                        try {
                            T_PPInfoColTableAdapter adapter = new T_PPInfoColTableAdapter();
                            int val = adapter.Delete(int.Parse(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "28"://CustomLable
                    {
                        try {
                            T_CustomLableTableAdapter adapter = new T_CustomLableTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "29"://Product2
                    {
                        try {
                            if (Id.IndexOf(" ") > 0) {
                                Id = Id.Replace(" ", "+");
                            }
                            if (Id2.IndexOf(" ") > 0) {
                                Id2 = Id2.Replace(" ", "+");
                            }
                            T_Product2TableAdapter adapter = new T_Product2TableAdapter();
                            int val = adapter.Delete(Id, Id2);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;

                case "31"://EbayUnSendCountry
                    {
                        try {
                            T_EbayUnSendCountryTableAdapter adapter = new T_EbayUnSendCountryTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "32"://OrderSource
                    {
                        try {
                            T_OrderSourceTableAdapter adapter = new T_OrderSourceTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "33"://RoymailAndPayPalSendCountry
                    {
                        try {
                            T_RoymailAndPayPalSendCountryTableAdapter adapter = new T_RoymailAndPayPalSendCountryTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "34"://ExpressShippingMethods
                    {
                        try {
                            T_ExpressShippingMethodsTableAdapter adapter = new T_ExpressShippingMethodsTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "35"://Postage
                    {
                        try {
                            T_PostageTableAdapter adapter = new T_PostageTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "36": //CreateDocumentsType
                    {
                        try {
                            T_CreateDocumentsTypeTableAdapter adapter = new T_CreateDocumentsTypeTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "37"://Modle
                    {
                        try {
                            T_ModleTableAdapter adapter = new T_ModleTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "39"://Country
                    {
                        try {
                            T_CountryTableAdapter adapter = new T_CountryTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "40"://RefundType
                    {
                        try {
                            T_RefundTypeTableAdapter adapter = new T_RefundTypeTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "49"://RealPostage
                    {
                        try {
                            T_RealPostageTableAdapter adapter = new T_RealPostageTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "50"://RealPostage
                    {
                        try {
                            T_EbayCountryTableAdapter adapter = new T_EbayCountryTableAdapter();
                            int val = adapter.Delete(Convert.ToInt32(Id));
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "51"://RealPostage
                    {
                        try {
                            T_CountryCategoryTableAdapter adapter = new T_CountryCategoryTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "52"://ReBuilderReason 重发原因
                    {
                        try {
                            T_ReBuilderReasonTableAdapter adapter = new T_ReBuilderReasonTableAdapter();
                            int val = adapter.Delete(Id);
                            if (val > 0) {

                                tableSource = GetMsgTable("0", "删除成功!");
                            } else {
                                tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                            }
                        } catch {
                            tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                        }
                    }
                    break;
                case "53"://CustomerResolve 商品
                    {
                        string ebayUserId = Request["ebId"];
                        string orderlineItemId = Request["olId"];
                        string productId = Request["pId"];
                        bool check = true;
                        if (check) {
                            string cmdText = @"select OrderStatusId from Orders where EbayUserId =@EbayUserId and OrderLineItemId =@OrderLineItemId ";
                            SqlParameter[] p = { 
                                new SqlParameter("@EbayUserId",SqlDbType.VarChar),
                                new SqlParameter("@OrderLineItemId",SqlDbType.VarChar)
                            };
                            p[0].Value = ebayUserId;
                            p[1].Value = orderlineItemId;
                            try {
                                DataTable table = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, cmdText, p);
                                if (table.Rows.Count > 0) {
                                    DataRow row = table.Rows[0];
                                    string val = row["OrderStatusId"].ToString();
                                    if (val == "2") {
                                        tableSource = GetMsgTable("1", "订单已审核不能操作");
                                        check = false;
                                    }
                                }
                            } catch (Exception ex) {
                                Log.WriteLog(ex.ToString());
                                tableSource = GetMsgTable("1", "服务器内部错误!");
                                check = false;
                            }
                        }

                        if (check) {
                            string cmdText2 = @"delete From CustomerResolve where EbayUserId =@EbayUserId and OrderLineItemId =@OrderLineItemId and ProductId =@ProductId";
                            SqlParameter[] p2 = {
                                new SqlParameter ("@EbayUserId",SqlDbType.VarChar),
                                new SqlParameter ("@OrderLineItemId",SqlDbType.VarChar),
                                new SqlParameter ("@ProductId",SqlDbType.VarChar)
                            };
                            p2[0].Value = ebayUserId;
                            p2[1].Value = orderlineItemId;
                            p2[2].Value = productId;

                            SqlParameter[] parameters = new SqlParameter[] {
                                new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = ebayUserId },
                                new SqlParameter() { ParameterName = "@OrderLineItemID", SqlDbType = SqlDbType.NVarChar, Size = 30, Value = orderlineItemId }
                            };

                            using (SqlConnection connection = new SqlConnection(SqlHelper.ceterDB_Conn)) {
                                connection.Open();
                                using (SqlTransaction tran = connection.BeginTransaction()) {
                                    int val = SqlHelper.ExecuteNonQuery(tran, CommandType.Text, cmdText2, p2);
                                    SqlHelper.ExecuteNonQuery(tran, CommandType.Text, SqlHelper.UpdateProfitCenterString, parameters);

                                    try {
                                        tran.Commit();
                                        tableSource = val > 0 ? GetMsgTable("0", "删除成功!") : GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                                    } catch (Exception ex) {
                                        Log.WriteLog(ex.ToString());
                                        tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                                    }
                                }
                            }
                        }
                    }
                    break;
                case "54": {
                    try {
                        String sqlString = "DELETE eBayFeedbackFollowType WHERE ID=@ID";
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@ID", SqlDbType = SqlDbType.Int, Value = Id }
                        };
                        int val = SqlHelper.ExecuteNonQuery(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                        if (val > 0) {
                            tableSource = GetMsgTable("0", "删除成功!");
                        } else {
                            tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                        }
                    } catch {
                        tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                    }
                }
                    break;
                case "55":
                    try {
                        String sqlString = "DELETE MailUsers WHERE ID=@ID";
                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter() { ParameterName = "@ID", SqlDbType = SqlDbType.Int, Value = Id }
                        };
                        int val = SqlHelper.ExecuteNonQuery(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);
                        if (val > 0) {
                            tableSource = GetMsgTable("0", "删除成功!");
                        } else {
                            tableSource = GetMsgTable("1", "删除失败,该行可能已被删除,请刷新界面后重试!");
                        }
                    } catch {
                        tableSource = GetMsgTable("1", "删除失败!,服务器内部错误!");
                    }
                    break;
                default:
                    tableSource = GetMsgTable("1", "删除失败!参数错误!");
                    break;
              }
              break;
#endregion

          case "l": {
              string userId = Request["uid"];
              string pwd = Request["pwd"];
              string chkCode = Request["code"];
              if (Session["CheckCode"] == null) {
                  tableSource = GetMsgTable("1003", "验证码错误,请刷新验证码");
              }
              if (chkCode.ToLower() != Session["CheckCode"].ToString().ToLower()) {
                  tableSource = GetMsgTable("1003", "验证码输入错误");
              } else {
                  chkCode = chkCode.ToLower();
                  T_UsersTableAdapter userAdapter = new T_UsersTableAdapter();
                  ebay.Dal.CenterDB_System.T_UsersDataTable userTable = userAdapter.GetUserByUserId(userId);
                  if (userTable.Rows.Count > 0) {
                      string origpass = userTable.Rows[0]["PassWord"].ToString();
                      string encpass = EncryptC.Md532(origpass + chkCode);
                      if (pwd != encpass) {
                          tableSource = GetMsgTable("1004", "密码错误");
                      } else {
                          Session["UserId"] = userId;
                          Session["UserName"] = userTable.Rows[0]["UserName"].ToString();
                          Session["FitemId"] = userTable.Rows[0]["FitemId"].ToString();
                          tableSource = GetMsgTable("0", "");
                      }
                  } else {
                      tableSource = GetMsgTable("1005", "用户名不正确");
                  }
              }
          }
              break;
          case "m": {
              String eBayUserID = Request["ebayuserid"];
              try {
                  String sqlString = "SELECT 1 FROM eBayAccount WHERE eBayUserID=@eBayUserID";
                  SqlParameter[] parameters = new SqlParameter[]{
                      new SqlParameter() { ParameterName = "@eBayUserID", SqlDbType = SqlDbType.NVarChar, Size = 80, Value = eBayUserID }
                  };
                  DataTable dataSource = SqlHelper.ExecuteDataTable(SqlHelper.ceterDB_Conn, CommandType.Text, sqlString, parameters);

                  if (dataSource != null && dataSource.Rows.Count > 0) {
                      Session["eBayUserID"] = eBayUserID;
                      tableSource = GetMsgTable("0", "");
                  } else {
                      tableSource = GetMsgTable("1008", "所选账户不存在...");
                  }
              } catch (System.Exception ex) {
                  tableSource = GetMsgTable("1", "数据库查询出错, 错误代码: " + ex.Message + "...");
              }
          }
              break;
          case "chklg": {
              if (Session["UserId"] == null) {
                  tableSource = GetMsgTable("1001", "您还没有登陆");
              } else {
                  string url = Request["curl"];
                  if (!string.IsNullOrEmpty(url)) {
                      url = WebUtility.InputText(url, 255);
                      url = HttpUtility.UrlDecode(url);
                      url = url.IndexOf('?') > 0 ? url.Substring(0, url.IndexOf('?')) : url;
                      string userId = Session["UserId"].ToString();
                      T_UserRightTableAdapter adapter = new T_UserRightTableAdapter();
                      if (Convert.ToInt32(adapter.IsExistsRight(userId, url)) <= 0) {
                          tableSource = GetMsgTable("1002", "您没有此权限");
                      } else {
                          tableSource = GetMsgTable("0", "");

                      }
                  } else {
                      tableSource = GetMsgTable("0", "");
                  }
              }
          }
              break;
          default:
              tableSource = new DataTable();
              break;
        }
        if (tableSource != null) {
            _jsonRows = GetJson(tableSource);
        }
        string jsonReault = null;
        if (type == "0") {
            jsonReault = "{\"total\":" + rowCount + ",\"rows\":" + _jsonRows + "}";
        } else if (type == "1") {
            jsonReault = _jsonRows;
        } else if (type == "2") {
            //jsonReault = _jsonRows;
            Response.ContentType = "text/plain";
            jsonReault = getAutoCompleteResult(tableSource);
        }
        Response.Write(jsonReault);
    }

    string getAutoCompleteResult(DataTable tableSouce) {
        if (tableSouce == null)
            return "";
        StringBuilder result = new StringBuilder();
        int cCount = tableSouce.Columns.Count;
        int rCount = tableSouce.Rows.Count;
        for (int i = 0; i < rCount; i++) {
            result.Append(tableSouce.Rows[i][0]);
            for (int j = 1; j < cCount; j++) {
                result.Append("|").Append(tableSouce.Rows[i][j]);
            }
            result.Append("\n");
        }
        return result.ToString();
    }

    DataTable GetMsgTable(string code, string msg) {
        DataTable tableSource = new DataTable();
        tableSource.Columns.Add("code");
        tableSource.Columns.Add("msg");
        tableSource.Rows.Add(code, msg);
        return tableSource;
    }

    string GetJson(DataTable tableSouce) {
        ebay.Jasp.JSONArray jsonArr = ebay.Jasp.Data.GetJsonList(tableSouce);
        return ebay.Jasp.json.SerializeArray(jsonArr);
    }
}
